package cn.iocoder.yudao.module.system.service.facecompany;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.facecompany.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.facecompany.FaceCompanyDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.system.dal.mysql.facecompany.FaceCompanyMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 面试公司 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class FaceCompanyServiceImpl implements FaceCompanyService {

    @Resource
    private FaceCompanyMapper faceCompanyMapper;

    @Override
    public Long createFaceCompany(FaceCompanySaveReqVO createReqVO) {
        // 插入
        FaceCompanyDO faceCompany = BeanUtils.toBean(createReqVO, FaceCompanyDO.class);
        faceCompanyMapper.insert(faceCompany);
        // 返回
        return faceCompany.getId();
    }

    @Override
    public void updateFaceCompany(FaceCompanySaveReqVO updateReqVO) {
        // 校验存在
        validateFaceCompanyExists(updateReqVO.getId());
        // 更新
        FaceCompanyDO updateObj = BeanUtils.toBean(updateReqVO, FaceCompanyDO.class);
        faceCompanyMapper.updateById(updateObj);
    }

    @Override
    public void deleteFaceCompany(Long id) {
        // 校验存在
        validateFaceCompanyExists(id);
        // 删除
        faceCompanyMapper.deleteById(id);
    }

    private void validateFaceCompanyExists(Long id) {
        if (faceCompanyMapper.selectById(id) == null) {
            throw exception(FACE_COMPANY_NOT_EXISTS);
        }
    }

    @Override
    public FaceCompanyDO getFaceCompany(Long id) {
        return faceCompanyMapper.selectById(id);
    }

    @Override
    public PageResult<FaceCompanyDO> getFaceCompanyPage(FaceCompanyPageReqVO pageReqVO) {
        return faceCompanyMapper.selectPage(pageReqVO);
    }

}